package io.renren.modules.hos.controller;

import com.alipay.api.AlipayApiException;
import io.renren.common.utils.R;
import io.renren.modules.hos.entity.AppointmentEntity;
import io.renren.modules.hos.form.AliPayForm;
import io.renren.modules.hos.service.AppointmentService;
import io.renren.modules.hos.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("hos")
public class PayController {
    @Autowired
    private PayService payService;

    @RequestMapping("/appointment/pay")
    public String appointmentPay(@RequestParam String outTradeNo,
                            @RequestParam String subject,
                            @RequestParam String totalAmount,
                            @RequestParam String body) throws AlipayApiException {
        AliPayForm alipayBean = new AliPayForm();
        alipayBean.setOut_trade_no(outTradeNo); //订单号
        alipayBean.setSubject(subject);         //商品名
        alipayBean.setTotal_amount(totalAmount);//总价格
        alipayBean.setBody(body);

        return payService.appointmentPay(alipayBean);
    }

    @GetMapping("/order/pay")
    public String orderPay(@RequestParam String outTradeNo,
                                 @RequestParam String subject,
                                 @RequestParam String totalAmount,
                                 @RequestParam String body) throws AlipayApiException {
        AliPayForm alipayBean = new AliPayForm();
        alipayBean.setOut_trade_no(outTradeNo); //订单号
        alipayBean.setSubject(subject);         //商品名
        alipayBean.setTotal_amount(totalAmount);//总价格
        alipayBean.setBody(body);

        return payService.orderPay(alipayBean);
    }
}
